package com.example.demo.com.example.proxy.jdkproxy.dynamic;

import com.example.demo.com.example.proxy.jdkproxy.GPClassLoader;
import com.example.demo.com.example.proxy.jdkproxy.GPInvocationHandler;
import com.example.demo.com.example.proxy.jdkproxy.GPProxy;
import com.example.demo.com.example.proxy.dynamic.Person;

import java.lang.reflect.Method;

public class GPJDKMeipo implements GPInvocationHandler {

    private Person target;

    public Object getInstance(Person target){
        this.target = target;
        return GPProxy.newProxyInstance(new GPClassLoader(),target.getClass().getInterfaces(),this);
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Exception {
        before();
        Object obj = method.invoke(this.target,args);
        after();
        return null;
    }


    private void after() {
        System.out.println("可以结婚了");

    }

    private void before() {

        System.out.println("我是媒婆，大家好");
        System.out.println("我要物色了，漂亮的");
    }
}
